package com.atcjx.service;

import com.atcjx.MyUtils.DateUtils;
import com.atcjx.MyUtils.File.UploadUtil;
import com.atcjx.config.PathConfig;
import com.atcjx.exception.UserException;
import com.atcjx.mapper.FileMapper;
import com.atcjx.mapper.UserMapper;
import com.atcjx.pojo.File.Img;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName UploadServiceImpl.java
 * @Description TODO
 * @createTime 2021年09月27日 19:27:00
 */
@Service
public class UploadServiceImpl  {

    @Autowired
    PathConfig pathConfig;

    @Autowired
    FileMapper fileMapper;

    public String uploadImg(List<MultipartFile> fileList, HttpServletRequest request) throws UserException {
        return UploadUtil.upload(fileList,request,pathConfig.getImgFilePath());
    }
    public String uploadMdFIle(MultipartFile fileList, HttpServletRequest request) throws UserException {
        return UploadUtil.uploadMdFile(fileList, request, pathConfig.getMdFilePath());
    }

    public void storeURL(String url,String baseURL) {
        fileMapper.addImgUrl(new Img(url,baseURL,new Date().getTime()));
    }


    public boolean checkBaseURL(String requestURL) {
        int i = fileMapper.checkURLExist(requestURL);
        return i != 0;
    }
}

